﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EventWriter
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        List<String> m_country;
        List<String> m_Scopes;

        public Window1()
        {
            InitializeComponent();
            m_country = new List<String>();
            m_Scopes = new List<String>();
            m_Scopes.Add("Country");
            m_Scopes.Add("Province");
            m_Scopes.Add("None");

            XMLDOC.writeXML();
            XMLDOC.readXML(ref m_country);
            // listbox1;
            listBox1.Items.Add("Scope 1");
            listBox1.Items.Add("Scope 2");
            listBox1.Items.Add("Scope 3");
            listBox1.Items.Add("Scope 4");
            // listbox2;
            foreach (String x in m_country)
            {
                listBox2.Items.Add(x);
            }
            this.listBox2.PreviewMouseMove += new MouseEventHandler(listBox2_PreviewMouseMove);
            this.richTextBox1.DragOver += new DragEventHandler(richTextBox1_DragOver);
            this.richTextBox1.Drop += new DragEventHandler(richTextBox1_Drop);
           
            
        }

        private void listBox2_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (listBox2.SelectedItem == null) return;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DataObject data = new DataObject(listBox2.SelectedItem);
                DragDrop.DoDragDrop(listBox2, data, DragDropEffects.Copy | DragDropEffects.Move);
            } 
        }

        private void richTextBox1_DragOver(object sender, DragEventArgs e)
        {
            int SelItem = listBox2.SelectedIndex;
            if ( -1 != SelItem)
            {
                e.Effects = DragDropEffects.Copy;
            }
            e.Effects = DragDropEffects.None;
        }
        private void richTextBox1_Drop(object sender, DragEventArgs e)
        {
            object CurSelItem = e.Data.GetData(typeof(ListBoxItem));
            string str = CurSelItem.ToString();
            richTextBox1.AppendText(str);
        }

        private void ScopeChange(object sender, SelectionChangedEventArgs e)
        {
            listBox2.Items.Clear();
            
            if ( null != listBox1.SelectedItem)
            {
                object CurScope = listBox1.SelectedItem;
                String s = CurScope.ToString();
                listBox2.Items.Add(s);
            }
            
        }
    }
}
